package com.varian.system.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.varian.log.annotation.ApiLog;
import com.varian.service.annotation.Resubmit;
import com.varian.service.web.BaseController;
import com.varian.system.dto.SysParamDTO;
import com.varian.system.dto.SysParamPageDTO;
import com.varian.system.service.ISysParamService;
import com.varian.system.vo.SysParamVO;
import com.varian.tool.result.IR;
import com.varian.tool.result.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author ben
 * @since 2025/2/9
 */
@Resubmit
@RestController
@Tag(name = "系统参数控制层")
@RequestMapping("/param")
public class SysParamController extends BaseController<ISysParamService> {

    @ApiLog
    @Operation(summary = "新增系统参数")
    @PostMapping
    @PreAuthorize("hasAuthority('param:add')")
    public IR add(@Validated @RequestBody SysParamDTO dto) {
        return R.status(baseService.add(dto));
    }

    @ApiLog
    @Operation(summary = "系统参数分页")
    @GetMapping("page")
    @PreAuthorize("hasAuthority('param:page')")
    public R<Page<SysParamVO>> page(@Validated SysParamPageDTO dto){
        return R.data(baseService.page(dto));
    }

    @ApiLog
    @Operation(summary = "系统参数详情")
    @GetMapping("{id:\\d+}")
    @PreAuthorize("hasAuthority('param:detail')")
    public R<SysParamVO> detail(@PathVariable("id") Long id) {
        return R.data(baseService.detail(id));
    }

    @ApiLog
    @Operation(summary = "修改系统参数")
    @PutMapping("{id:\\d+}")
    @PreAuthorize("hasAuthority('param:modify')")
    public IR modify(@PathVariable("id") Long id, @Validated @RequestBody SysParamDTO dto) {
        return R.status(baseService.modify(id, dto));
    }

    @ApiLog
    @Operation(summary = "删除系统参数")
    @DeleteMapping("{id:\\d+}")
    @PreAuthorize("hasAuthority('param:delete')")
    public IR delete(@PathVariable("id") Long id) {
        return R.status(baseService.delete(id));
    }

}
